package org.scmpatrol.scm;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * Represent a path in the scm system
 * <p/>
 * User: vincent.sellier
 * Date: May 5, 2009
 * Time: 12:20:18 AM
 */
@Entity
@Table(name = "path")
public class SCMPath implements Serializable {

	private static final long serialVersionUID = -4204785853154095467L;

	Long id;
    String path;

    public SCMPath() {
        // for persistence use only
    }

    public SCMPath(String path) {
        this.path = path;
    	if (! path.startsWith("/")) {
    		this.path = "/" + this.path;
    	}
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SCMPath other = (SCMPath) obj;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		return true;
	}
    
    
    
}
